<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <title>KingBes Admin 安装</title>
    <link rel="stylesheet" href="/pear/css/pear.css" />
</head>

<body class="pear-container">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card">
                    <div class="layui-card-body" style="padding-top: 40px;">
                        <h1 style="text-align:center;margin: 20px 0 40px">KingBes Admin 安装</h1>

                        <form class="layui-form layui-form-pane" action=""
                            style="width: 520px;max-width: 100%;margin: 0 auto;">
                            <div class="layui-form-item">
                                <label class="layui-form-label">用户名</label>
                                <div class="layui-input-block">
                                    <input type="text" name="user" autocomplete="off" placeholder="请输入用户名"
                                        lay-verify="required" class="layui-input" value="root">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="password" autocomplete="off" placeholder="请输入密码"
                                        lay-verify="required" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">数据库</label>
                                <div class="layui-input-block">
                                    <input type="text" name="database" autocomplete="off" placeholder="请输入数据库"
                                        lay-verify="required" class="layui-input" value="kb_admin">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">host</label>
                                <div class="layui-input-block">
                                    <input type="text" name="host" autocomplete="off" placeholder="请输入数据库host"
                                        lay-verify="required" class="layui-input" value="127.0.0.1">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">端口</label>
                                <div class="layui-input-block">
                                    <input type="number" name="port" autocomplete="off" placeholder="请输入数据库端口"
                                        lay-verify="required" class="layui-input" value="3306">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">后台用户名</label>
                                <div class="layui-input-block">
                                    <input type="text" name="adminuser" autocomplete="off" placeholder="请输入后台用户名"
                                        lay-verify="required" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">后台密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="adminpwd" autocomplete="off" placeholder="请输入后台密码"
                                        lay-verify="required" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">确认密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="adminpwd_confirm" autocomplete="off"
                                        placeholder="请再次输入后台密码" lay-verify="required" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <button class="layui-btn" lay-submit lay-filter="submit">确认</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <script src="/layui/layui.js"></script>
    <script src="/pear/pear.js"></script>

    <script>
        layui.use(["form", "layer", "element", "jquery", "common"], function () {
            let $ = layui.$,
                form = layui.form,
                layer = layui.layer,
                element = layui.element,
                common = layui.common

            let layerform = $("form");

            form.on('submit(submit)', function (data) {
                let load = layer.msg('安装中，请耐心等待', {
                    icon: 16,
                    shade: 0.01
                });
                $.ajax({
                    url: "{:route('admin.install.index')}",
                    type: "post",
                    data: data.field,
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 1) {
                            layer.msg(res.msg, { icon: res.code }, function () {
                                layer.close(load)
                                window.location.href = "{:route('admin.login.index')}";
                            });
                        } else {
                            layer.close(load)
                            if (res.data != "") {
                                common.validate(layerform, res.data, res.msg);
                            } else {
                                layer.msg(res.msg, { icon: res.code });
                            }
                        }
                    },
                    error: function () {
                        layer.close(load)
                        layer.msg('网络异常', { icon: 2 });
                    }
                })
                return false;
            })
        })
    </script>
</body>

</html>